package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.AssortContent;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by haojiayao on 16-08-02.
 */
public class AssortContentConvert {

    public static DBObject castAssortContentToDBObject(AssortContent assortContent) {

        DBObject dbo = new BasicDBObject();
        if (assortContent.getId() != null) {
            dbo.put("_id", assortContent.getId());
        }
        dbo.put("assortId", assortContent.getAssortId());
        dbo.put("programId", assortContent.getProgramId());
        dbo.put("pType", assortContent.getPType());
        dbo.put("priority", ObjectUtils.toLong(assortContent.getPriority(), 0L));
        dbo.put("startTime", assortContent.getStartTime());
        dbo.put("createTime", ObjectUtils.toLong(assortContent.getCreateTime(), System.currentTimeMillis()));
        dbo.put("updateTime", System.currentTimeMillis());
        return dbo;
    }

    public static AssortContent castDBObjectToAssortContent(DBObject dbObject) {

        AssortContent assortContent = new AssortContent();
        if (dbObject != null) {
            assortContent.setId(ObjUtils.toLong(dbObject.get("_id")));
            assortContent.setAssortId(ObjUtils.toLong(dbObject.get("assortId")));
            assortContent.setProgramId(ObjUtils.toLong(dbObject.get("programId")));
            assortContent.setPType(ObjectUtils.toInteger(dbObject.get("pType")));
            assortContent.setPriority(ObjUtils.toLong(dbObject.get("priority")));
            assortContent.setStartTime(ObjUtils.toLong(dbObject.get("startTime")));
            assortContent.setCreateTime(ObjUtils.toLong(dbObject.get("createTime")));
            assortContent.setUpdateTime(ObjUtils.toLong(dbObject.get("updateTime")));
        } else {

            return null;
        }
        return assortContent;
    }
}
